package com.p595263720.o_amap.map.models;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.p595263720.o_amap.OAmapPlugin;

import java.io.IOException;
import java.io.InputStream;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.view.FlutterMain;

public class UnifiedAssets {

    /**
     * 获取宿主app的图片
     */
    public static BitmapDescriptor getBitmapDescriptor(String asset, Context context) {
        try {
            String res  = FlutterMain.getLookupKeyForAsset(asset);
            AssetManager manager = context.getAssets();
            InputStream in =  manager.open(res);
            Bitmap bitmap = BitmapFactory.decodeStream(in);
            return BitmapDescriptorFactory.fromBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取plugin自带的图片
     */
    public static BitmapDescriptor getDefaultBitmapDescriptor(String asset) {
        return BitmapDescriptorFactory.fromAsset(FlutterMain.getLookupKeyForAsset(asset, "com.p595263720.zit"));
    }
}
